package com.wondream.myframework.design_pattern.prototype;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.joda.time.DateTime;

/**
 * 原型模式-大批量生成对象的时候，通过内存拷贝提高性能
 * 实现clonable接口
 */
@Data
@AllArgsConstructor
public class ShortMessage implements Cloneable {
    private String title;
    private String mobile;
    private String content;
    private String clientName;
    private String companyName;

    public ShortMessage(String title, String companyName) {
        this.title = title;
        this.companyName = companyName;
    }

    public static void main(String[] args) throws Exception {
        long start = new DateTime().getMillis();
        ShortMessage shortMessage = new ShortMessage("2023年618年中促销", "天猫商超");
        ShortMessage sendMessage = null;
        for (int i = 0; i < 5000; i++) {
            sendMessage = (ShortMessage)shortMessage.clone();
            sendMessage.setMobile(""+i);
            System.out.println(new ObjectMapper().writeValueAsString(sendMessage));
//            sendMessage();
        }
    }
}
